package jjoms.model.item;


import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;
@Repository
public class ItemDAOImpl implements ItemDAO {
	@Resource(name="sqlSessionTemplate")
	   private SqlSessionTemplate sqlSessionTemplate;

	@Override 
	public List<ItemVO> getItemList(String keyword) {
		System.out.println("getItemList-DAO"+keyword);
		return sqlSessionTemplate.selectList("item.getItemList",keyword);
	}   
	@Override
	public void register(ItemVO vo) {
		System.out.println("DAO : "+vo);
		sqlSessionTemplate.insert("item.register",vo);
	}

	@Override
	public ItemVO findItemByName(String name) {
		return sqlSessionTemplate.selectOne("item.findItemByName",name);
	}
	@Override
	public ItemVO getItemContent(int itemNo) {
		return sqlSessionTemplate.selectOne("item.getItemContent",itemNo);
	}
	@Override
	public void update(ItemVO vo) {
		sqlSessionTemplate.update("item.update",vo);
	}
	@Override
	public void delete(int itemNo) {
		sqlSessionTemplate.delete("item.delete",itemNo);
		
	}
	@Override
	public List<String> getCategory() {
		return sqlSessionTemplate.selectList("item.getCategory");
	}
	@Override
	public List<String> getDivision(String category) {
		return sqlSessionTemplate.selectList("item.getDivision",category);
	}
	@Override
	public void addCart(CartVO cvo) {
		System.out.println("addCart DAO 실행됨 == "+cvo);
		sqlSessionTemplate.insert("item.addCart",cvo);
		
	}
	@Override
	public void postResult(PostVO pvo) {
		System.out.println("postResult DAO 실행됨 == "+pvo);
		sqlSessionTemplate.insert("item.postResult",pvo);
		
	}
	@Override
	public void totalPay(HashMap map){
		sqlSessionTemplate.update("member.totalPay",map);
	}
	@Override
	public void pointUp(HashMap map) {
		sqlSessionTemplate.update("member.pointUp",map);

	}
	public List<PostVO> getPostHuki(String itemName) {
		return sqlSessionTemplate.selectList("item.getPostHuki",itemName);


	}
	
	public List<PostVO> getPostHuki(int itemNo) {
		return sqlSessionTemplate.selectList("item.getPostHukiToitemNo",itemNo);
	}
	@Override
	public void insertToPurchasedList(ItemVO vo){
		System.out.println("구매목록에 넣기"+ vo);
		sqlSessionTemplate.insert("item.insertToPurchasedList",vo);
		System.out.println("구매목록 넣기 완료");
	}
	@Override
	public List<ItemVO> getPurchasedList(String memberId){
		System.out.println("구매목록 불러오기"+memberId);
		return sqlSessionTemplate.selectList("item.getPurchasedList",memberId);
	}
	@Override
	public int getAverageEvaluation(int itemNo){
		return sqlSessionTemplate.selectOne("item.getAverageEvaluation",itemNo);
	}
	@Override
	public void sendMessage(MessageVO messvo){
		sqlSessionTemplate.insert("item.sendMessage",messvo);
	}
	@Override
	public List<CartVO> getCartList(String memberId) {
		return sqlSessionTemplate.selectList("item.getCartList",memberId);
	}
	@Override
	public ItemVO getCartInfoList(int itemNo) {
		System.out.println("cartInfoDAO =="+itemNo);
		return sqlSessionTemplate.selectOne("item.getCartInfoList",itemNo);
	}
	@Override
	public int countCart(int itemNo) {
		System.out.println("DAO == "+itemNo);
		return sqlSessionTemplate.selectOne("item.countCart",itemNo);
	}
	@Override
	public void postDelete(PostVO pvo) {
		sqlSessionTemplate.delete("item.postDelete",pvo);
	}
	@Override
	public List<ItemVO> showUploadList(String memberId){
		return sqlSessionTemplate.selectList("item.showUploadList",memberId);
	}
	@Override
	public void withdraw(String memberId, int getItemPrice)throws Exception{
		ItemVO ivo = new ItemVO();
		ivo.setItemPrice(getItemPrice);
		ivo.setMemberId(memberId);
		System.out.println("withdraw IVO : " + ivo);
		this.sqlSessionTemplate.update("item.withdraw", ivo);
	}
	@Override
	public void deposit(String memberId, int getItemPrice) throws Exception{
		ItemVO ivo = new ItemVO();
		ivo.setItemPrice(getItemPrice);
		ivo.setMemberId(memberId);
		System.out.println("withdraw IVO : " + ivo);
		this.sqlSessionTemplate.update("item.deposit", ivo);
	}
	@Override
	public void cartDelete(int no) {
		sqlSessionTemplate.delete("item.cartDelete",no);
		
	}
}
